<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0" />
        <title>2. 封装自己的数学对象</title>
    </head>
    <body>
        <script>
            // 模拟Math对象，编写的myMath对象
            var myMath = {
                PI: 3.1415926543,       // 属性
                max: function(){        // max方法
                    // 
                    if (0 == arguments.length) {
                        return -Infinity;
                    }
                    var max = arguments[0];
                    for(var i = 0; i < arguments.length; i++){
                        if(typeof arguments[i] !== 'number')
                            return NaN;
                        if(max < arguments[i])
                            max = arguments[i];
                    }
                    return max;
                },
                min: function(){        // min方法
                    // 
                    if (0 == arguments.length) {
                        return -Infinity;
                    }
                    var min = arguments[0];
                    for(var i = 0; i < arguments.length; i++){
                        if(typeof arguments[i] !== 'number')
                            return NaN;
                        if(min > arguments[i])
                            min = arguments[i];
                    }
                    return min;
                }
            }

            console.log(myMath.PI);
            console.log(myMath.max(1, 2, 4));
            console.log(myMath.max(1, 2, 'a'));
            console.log(myMath.max(1, 'a', 23));
            
            console.log(myMath.min(1, 2, 4));
            console.log(myMath.min(1, 2, 'a'));
            console.log(myMath.min(1, 'a', 23));
            
            
        </script>
    </body>
</html>